package com.neusoft.controller;

import com.neusoft.mapper.RedemptionRecordMapper;
import com.neusoft.po.CommonResult;
import com.neusoft.po.RedemptionRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/redemption")
public class RedemptionRecordController {

    @Autowired
    private RedemptionRecordMapper redemptionRecordMapper;

    // 用户兑换商品
    @PostMapping("/redeem/{userId}")
    public CommonResult redeemProduct(@PathVariable("userId") String userId,
                                      @RequestParam("productId") Integer productId) {
        // 这里假设已经处理了兑换逻辑，包括积分扣除和记录插入
        // 实际业务逻辑应在 Service 层处理
        return new CommonResult(200, "success", "Product redeemed successfully");
    }

    // 获取用户的兑换记录
    @GetMapping("/records/{userId}")
    public CommonResult getRedemptionRecordsByUserId(@PathVariable("userId") String userId) {
        List<RedemptionRecord> records = redemptionRecordMapper.getRedemptionRecordsByUserId(userId);
        return new CommonResult(200, "success", records);
    }
}